#include <sys/types.h>
#include <pwd.h>
#include <stdio.h>


/*
 * 通过用户的uid查找用户的passwd数据。如果出错时，它们都返回一个空指针并设置errno的值，用户可以根据perror函数查看出错的信息。
 */

#if 0

struct passwd *getpwuid(uid_t uid);

The passwd structure is defined in <pwd.h> as follows:

struct passwd {
    char *pw_name; /*user name */
    char *pw_passwd; /*user password */
    uid_t pw_uid; /*user id */
    gid_t pw_gid; /*group id */
    char *pw_gecos; /*user real name */
    char *pw_dir; /*home directory */
    char *pw_shell; /*shell program */
};

#endif

int main()
{
    uid_t my_uid;
    struct passwd *my_info;
    my_info =getpwuid( getuid() );
   
    printf( "my name = [%s]\n", my_info->pw_name );
    printf( "my passwd = [%s]\n", my_info->pw_passwd );
    printf( "my uid = [%d]\n", my_info->pw_uid );
    printf( "my gid = [%d]\n", my_info->pw_gid );
    printf( "my gecos = [%s]\n", my_info->pw_gecos );
    printf( "my dir = [%s]\n", my_info->pw_dir );
    printf( "my shell = [%s]\n", my_info->pw_shell );
    
    return 0;
}

#if 0
my name = [xiaozhi]
my passwd = [x]
my uid = [1000]
my gid = [1000]
my gecos = [ac,,,]
my dir = [/home/xiaozhi]
my shell = [/bin/bash]
#endif
